/**
 * @author yuyangyang
 * @time 2015/3/11
 */
var userService = require('../services/user');

module.exports = {
    mapping: '/user',
    get: {
        '/owner': function (req, res) {
            userService.queryById(req.session.userId, function (err, user) {
                res.json(user);
            });
        },
        '/logout': function (req, res) {
            req.session.userId = null;
            res.json(1);
        }
    },
    post: {
        '/register': function (req, res) {
            userService.addUser(req.body, function (err, data) {
                if (data) {
                    req.session.userId = data.id;
                }
                res.json(data);
            });
        },
        '/login': function (req, res) {
            userService.queryUser(req.body, function (err, data) {
                if (data) {
                    req.session.userId = data.id;
                }
                res.json(data);
            });
        }
    }
}